package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/29 11:52
 */
public class LS61 {

    public ListNode rotateRight(ListNode head, int k) {
        if (head == null) {
            return null;
        }

        int n = 1;
        ListNode node = head;
        while (node.next != null) {
            n++;
            node = node.next;
        }
        int add = n - k%n ;

        if (add == 0) {
            return head;
        }
        node.next = head;
        //计算长度
        while (add-- > 0) {
            node = node.next;
        }
        ListNode ret = node.next;
        node.next = null;
        return ret;



    }
}
